﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CLEXA.AdminClient.ViewModel
{
    internal sealed class UserReadVM : VMBase
    {
        private static readonly UserIdentityComparer identityComparer = new UserIdentityComparer();
        private readonly int userId;
        private readonly string username;
        private readonly bool isActive;

        public static IEqualityComparer<UserReadVM> IdentityComparer
        {
            get { return UserReadVM.identityComparer; }
        } 

        public int UserId
        {
            get { return userId; }
        }

        public string Username
        {
            get { return username; }
        }

        public bool IsActive
        {
            get { return isActive; }
        }

        public UserReadVM(int userId, string username, bool isActive)
        {
            this.userId = userId;
            this.username = username;
            this.isActive = isActive;
        }

        private sealed class UserIdentityComparer : IEqualityComparer<UserReadVM>
        {
            public bool Equals(UserReadVM x, UserReadVM y)
            {
                if (Object.ReferenceEquals(x, y))
                {
                    return true;
                }
                if (Object.ReferenceEquals(x, null))
                {
                    return false;
                }
                if (Object.ReferenceEquals(y, null))
                {
                    return false;
                }

                return x.userId == y.userId;
            }

            public int GetHashCode(UserReadVM obj)
            {
                if (Object.ReferenceEquals(obj, null))
                {
                    return 0;
                }

                return obj.userId.GetHashCode();
            }
        }
    }
}
